//
//  UIButton+Extension.swift
//  sinaOnceAgain
//
//  Created by 王相超 on 16/2/17.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

import UIKit
import SnapKit

extension UIButton {
    
    //给 UIButton 扩张一个  构造函数
    
    //背景图片   图片
    convenience init(backImageName: String?,imageName: String?) {
        
        self.init()
        
        if backImageName != nil {
            
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        
        if imageName != nil {
            
            setImage(UIImage(named: imageName!), forState: .Normal)
            
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
            sizeToFit()
        }
    }
    
    
    //背景图片  文案
    convenience init(backImageName: String?,title: String,textColor: UIColor,imageName: String? = nil,fontSize: CGFloat = 14) {
        
        self.init()
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
        //设置字体的大小
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        //适应大小
        sizeToFit()
    }
    
}









